<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 1.定义一个空数组
    let arr = []
    while (arr.length < 5){
      let num = +prompt(`用户输入第${arr.length + 1}个年龄：`)
      if (num > 0 && num < 100) {
        arr.push(num)
      }
    }
    console.log(arr)
    //打印所有成年人的年龄
    for (let i = 0; i < arr.length; i++) {
      if (arr[i] >= 18) {
       document.write(`已经成年的人的年龄为：${arr[i]}<br>`)
      }
    }

    // 打印出所有人总年龄
    let sum = 0
    for (let i = 0; i <arr.length; i++) {
      sum += arr[i]
    }
    document.write(`打印出所有人总年龄为${sum}<br>`)
    document.write(`打印出所有人平均年龄为${sum / arr.length}<br>`)

    let max = arr[0]
    for (let i = 1; i < arr.length; i++) {
      if (max < arr[i]) {
        max = arr[i]
      }
    }
    document.write(`最大值为${max}<br>`)

    let min = arr[0]
    for (let i = 1; i < arr.length; i++) {
      if (min > arr[i]) {
        min = arr[i]
      }
    }
    document.write(`最大值为${min}<br>`)


      
    
    
  </script>
</body>
</html>